﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Friedlich.Common;
using System.Xml.Linq;
using Friedlich.Web;

namespace Friedlich.RDF
{
    public class FOAF
    {
        public enum Fields
        {
            FirstName, LastName, Company, Title, School, Country, Zip, Headline, Location, Industry, Distance, Summary, Positions
        }

        public virtual ContactList Contacts
        {
            get;
            set;
        }

        public Contact CurrentUser { get; set; }

        public XDocument ToRDF() {

            XNamespace rdfNS = Namespaces.RDF;
            XNamespace foafNS = Namespaces.FOAF;
            XDocument xDoc = new XDocument();
            //XElement root = new XElement(rdfNS + "RDF",
            //    new XAttribute(XNamespace.Xmlns + "rdf", Namespaces.RDF),
            //    new XAttribute(XNamespace.Xmlns + "rdfs", Namespaces.RDFS),
            //    new XAttribute(XNamespace.Xmlns + "foaf", Namespaces.FOAF)
            //);
            XElement xRoot = new XElement(rdfNS + "RDF");
            if (Contacts != null && CurrentUser != null)
            {
                XElement xCurrentUser = CurrentUser.ToFoaf();
                foreach (Contact contact in Contacts)
                {

                    XElement knowsElem = new XElement(foafNS + "knows");
                    XElement personElem = contact.ToFoaf();
                    if (personElem != null)
                    {
                        knowsElem.Add(contact.ToFoaf());
                        xCurrentUser.Add(knowsElem);
                    }

                }                

                xRoot.Add(xCurrentUser);
            }
            
            xDoc.Add(xRoot);
            
            return xDoc;
        }
    }
}
